//
//  LongLetCarViewController.m
//  UcarTest
//
//  Created by 陈曦 on 16/3/13.
//  Copyright © 2016年 chenxi. All rights reserved.
//

#import "LongLetCarViewController.h"
#import "MainPageViewController.h"
#import "Define.h"
#import "AFNetworking.h"
#import "NetRequestGroup.h"
#import "Access_token.h"
#import "MBProgressHUD.h"
#import "UIImageView+WebCache.h"

@interface LongLetCarViewController ()

@property (nonatomic, strong) UISwitch *circleSwitch;

@property (nonatomic, strong) NSString *urlStr;

@end

@implementation LongLetCarViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    //导航条
    self.navigationController.navigationBarHidden = NO;
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.font = [UIFont boldSystemFontOfSize:18];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = @"长租车辆";
    self.navigationItem.titleView = titleLabel;
    self.navigationController.navigationBar.barTintColor = mainColor;
    self.view.backgroundColor = backgroundMainColor;
    
    
    //重定义返回键
    UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];
    back.frame = CGRectMake(0, 0, 22, 22);
    [back setImage:[UIImage imageNamed:@"iconfont-fanhui-white"] forState:UIControlStateNormal];
    [back addTarget:self action:@selector(backTpMainView) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backBar = [[UIBarButtonItem alloc] initWithCustomView:back];
    self.navigationItem.leftBarButtonItem = backBar;
    
    //网络请求
    [self NetworkRequests];


}


#pragma mark 网络请求
- (void) NetworkRequests{
    
    //初始化进度框，置于当前的View当中
    MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:HUD];
    HUD.label.text = @"正在加载";
    [HUD showAnimated:YES];//HUD开始
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    //申明返回的结果是json类型
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    //申明请求的数据是json类型
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    //如果报接受类型不一致请替换一致text/html或别的
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    Access_token *useAccess = [Access_token shareInstance];
    
    //传入的参数
    NSDictionary *para = @{
                           @"type" : @"1",
                           @"access_token" : useAccess.access_token
                           };
    //你的接口地址
    NSString *url = [NSString stringWithFormat:@"%@%@", kRealmName, kNetLongLetCar];
    //发送请求
    [manager POST:url parameters:para success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        
        
        NSDictionary *dic = responseObject;
        
        NSString *status = dic[@"status"];
        
        NSDictionary *info = dic[@"info"];
        
        self.carID = info[@"id"];
        self.rent_member_money = info[@"rent_member_money"];
        self.rent_money = info[@"rent_money"];
        self.rent_status = info[@"rent_status"];
        self.share_status = info[@"share_status"];
        self.brand = info[@"brand"];
        self.model = info[@"model"];
        self.end_time = info[@"end_time"];
        
        
        //字符串转换成时间戳
        NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[self.end_time intValue]];
        NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
        [dateFormat setDateFormat:@"yyyy/MM/dd"];
        self.end_time = [dateFormat stringFromDate:confromTimesp];
        
        
        //图片下载
        self.urlStr = [NSString stringWithFormat:@"%@%@", kRealmNameImage,info[@"left_img_small"]];
        
        //去除加载状态
        [HUD hideAnimated:YES];

        //布局
        [self distribution];
        

        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        [HUD hideAnimated:YES];
        
        //初始化提示框；
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"没有网络" preferredStyle:  UIAlertControllerStyleAlert];
        
        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            //点击按钮的响应事件；
        }]];
        
        //弹出提示框；
        [self presentViewController:alert animated:true completion:nil];

        
    }];
    
}

#pragma mark 布局
- (void) distribution {
    
    //1.第一部分--------------------------------------------------
    //车辆信息展示
    UIView *carInfoDemonstrateV = [[UIView alloc] initWithFrame:CGRectMake(10, 74, kScreenWidth - 20, kScreenWidth * 221 / 375 + 20)];
    carInfoDemonstrateV.backgroundColor = [UIColor whiteColor];
    carInfoDemonstrateV.layer.cornerRadius = 2;
    carInfoDemonstrateV.layer.shadowOpacity = 1.0;
    carInfoDemonstrateV.layer.shadowOffset = CGSizeMake(0.0, 0.0);
    carInfoDemonstrateV.layer.shadowColor = [UIColor grayColor].CGColor;
    carInfoDemonstrateV.layer.shadowRadius = 2.0;
    [self.view addSubview:carInfoDemonstrateV];
    
    //车辆图片
    self.carImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth - 20, kScreenWidth * 221 / 375 - 10)];
    [self.carImageV  sd_setImageWithURL:[NSURL URLWithString:self.urlStr]];

    self.carImageV.backgroundColor = [UIColor grayColor];
    self.carImageV.layer.cornerRadius = 2;
    self.carImageV.layer.masksToBounds = YES;
    [carInfoDemonstrateV addSubview:self.carImageV];
    
    //车辆信息标签
    UILabel *carInfoLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, kScreenWidth * 221 / 375 - 10, (kScreenWidth - 20) / 3, 30)];
    carInfoLabel.text = [NSString stringWithFormat:@"%@ %@", self.brand, self.model];
    carInfoLabel.textAlignment = NSTextAlignmentLeft;
    carInfoLabel.textColor = mainColor;
    carInfoLabel.font = [UIFont systemFontOfSize:15];
    [carInfoDemonstrateV addSubview:carInfoLabel];
    
    //date信息标签
    UILabel * dateInfoLabel = [[UILabel alloc] initWithFrame:CGRectMake((kScreenWidth - 20) / 3 + 10, kScreenWidth * 221 / 375 - 10, (kScreenWidth - 20) / 3 * 2 - 20, 30)];
    dateInfoLabel.text = [NSString stringWithFormat:@"使用截止日期: %@", self.end_time];
    dateInfoLabel.textAlignment = NSTextAlignmentRight;
    dateInfoLabel.textColor = [UIColor colorWithRed:102 / 255.0 green:102 / 255.0 blue:102 / 255.0 alpha:1];
    dateInfoLabel.font = [UIFont systemFontOfSize:15];
    [carInfoDemonstrateV addSubview:dateInfoLabel];
    
    
    
    //1.第二部分--------------------------------------------------
    //分享状态
    UIView *shareStatusBarV = [[UIView alloc] initWithFrame:CGRectMake(10, 114 + kScreenWidth * 221 / 375, kScreenWidth - 20, 98)];
    shareStatusBarV.backgroundColor = [UIColor whiteColor];
    shareStatusBarV.layer.cornerRadius = 2;
    shareStatusBarV.layer.shadowOpacity = 1.0;
    shareStatusBarV.layer.shadowOffset = CGSizeMake(0.0, 0.0);
    shareStatusBarV.layer.shadowColor = [UIColor grayColor].CGColor;
    shareStatusBarV.layer.shadowRadius = 2.0;
    [self.view addSubview:shareStatusBarV];

    UIView *demarcationLine = [[UIView alloc] initWithFrame:CGRectMake(5, 48.5, kScreenWidth - 30, 0.5)];//分界线
    demarcationLine.backgroundColor = lineColor;
    [shareStatusBarV addSubview:demarcationLine];
    
    //share标签
    UILabel *shareLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 16, 30, 15)];
    shareLabel.text = @"分享";
    shareLabel.textAlignment = NSTextAlignmentCenter;
    shareLabel.textColor = [UIColor colorWithRed:68 / 255.0 green:68 / 255.0 blue:68 / 255.0 alpha:1];
    shareLabel.font = [UIFont systemFontOfSize:15];
    [shareStatusBarV addSubview:shareLabel];
    
    //switch按钮
    self.circleSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(kScreenWidth - 85, 9, 50, 30)];
    
    if ([self.share_status isEqualToString:@"0"]) {
        self.circleSwitch.on = NO;
    } else if ([self.share_status isEqualToString:@"1"]) {
        self.circleSwitch.on = YES;
    }
    [self.circleSwitch addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];

    self.circleSwitch.onTintColor = mainColor;
    [shareStatusBarV addSubview:self.circleSwitch];
    
    //租金标签
    UILabel *moneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 66, 30, 15)];
    moneyLabel.text = @"租金";
    moneyLabel.textAlignment = NSTextAlignmentCenter;
    moneyLabel.textColor = [UIColor colorWithRed:68 / 255.0 green:68 / 255.0 blue:68 / 255.0 alpha:1];
    moneyLabel.font = [UIFont systemFontOfSize:15];
    [shareStatusBarV addSubview:moneyLabel];
    
    //租金区间
    self.meneyIntervalLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, 69, 200, 10)];
     self.meneyIntervalLabel.textColor = wordColor;
    
    NSInteger m = [self.rent_money integerValue];
    
    NSInteger a = m + m * 0.05;
    
    NSInteger b = m - m * 0.05;

     self.meneyIntervalLabel.text = [NSString stringWithFormat:@"租金区间为 %ld ~ %ld 元之间", b, a];
     self.meneyIntervalLabel.textAlignment = NSTextAlignmentLeft;
     self.meneyIntervalLabel.font = [UIFont systemFontOfSize:10];
    [shareStatusBarV addSubview: self.meneyIntervalLabel];
    
    
    //单位
    UILabel *uniteLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth - 40, 70, 10, 10)];
    uniteLabel.text = @"元";
    uniteLabel.textAlignment = NSTextAlignmentCenter;
    uniteLabel.textColor = [UIColor colorWithRed:68 / 255.0 green:68 / 255.0 blue:68 / 255.0 alpha:1];
    uniteLabel.font = [UIFont systemFontOfSize:10];
    [shareStatusBarV addSubview:uniteLabel];
    
    //租金价格
     self.setShareMoney = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth - 100 , 66, 60, 15)];
    self.setShareMoney.text = [NSString stringWithFormat:@"%@", self.rent_member_money];
    self.setShareMoney.textColor = mainColor;
    self.setShareMoney.textAlignment = NSTextAlignmentRight;
    self.setShareMoney.font = [UIFont systemFontOfSize:15];
    [shareStatusBarV addSubview:self.setShareMoney];
    
    //租金设置跳转页面
    self.setMoneyBtn = [UIButton buttonWithType:UIButtonTypeCustom ];
    self.setMoneyBtn.frame = CGRectMake(kScreenWidth - 100 , 66, 60, 15);
    [self.setMoneyBtn addTarget:self action:@selector(ReplenishSetRenterMoney) forControlEvents:UIControlEventTouchUpInside];
    [shareStatusBarV addSubview:self.setMoneyBtn];
 
    //创建一个轻拍手势 回收键盘
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)];
    
    [self.view addGestureRecognizer:tap];
}


#pragma mark switch监听响应事件
-(void)switchAction:(id)sender
{
    UISwitch *switchButton = (UISwitch*)sender;
    BOOL isButtonOn = [switchButton isOn];
    if (isButtonOn) {
        
        [self NetworkRequestsOn];
        
    }else {

        [self NetworkRequestsOff];

    }
}


#pragma mark 网络请求
- (void) NetworkRequestsOn{
    
    //初始化进度框，置于当前的View当中
    MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:HUD];
    HUD.label.text = @"正在加载";
    [HUD showAnimated:YES];//HUD开始
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    //申明返回的结果是json类型
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    //申明请求的数据是json类型
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    //如果报接受类型不一致请替换一致text/html或别的
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    Access_token *useAccess = [Access_token shareInstance];
    
    //传入的参数
    NSDictionary *para = @{
                           @"type" : @"1",
                           @"access_token" : useAccess.access_token,
                           @"share_status" : @"1"
                           };
    //你的接口地址
    NSString *url = [NSString stringWithFormat:@"%@%@", kRealmName,kNetUISwich];
    //发送请求
    [manager POST:url parameters:para success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        [HUD hideAnimated:YES];
        
        NSDictionary *dic = responseObject;
        
        self.status = dic[@"status"];
        
        self.msg = dic[@"msg"];

        [self resultAnalysis];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        [HUD hideAnimated:YES];
        
        //初始化提示框；
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"没有网络" preferredStyle:  UIAlertControllerStyleAlert];
        
        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            //点击按钮的响应事件；
        }]];
        
        //弹出提示框；
        [self presentViewController:alert animated:true completion:nil];
        
    }];
    
}

- (void) NetworkRequestsOff{
    
    //初始化进度框，置于当前的View当中
    MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:HUD];
    HUD.label.text = @"正在加载";
    [HUD showAnimated:YES];//HUD开始
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    //申明返回的结果是json类型
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    //申明请求的数据是json类型
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    //如果报接受类型不一致请替换一致text/html或别的
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    Access_token *useAccess = [Access_token shareInstance];
    
    //传入的参数
    NSDictionary *para = @{
                           @"type" : @"1",
                           @"access_token" : useAccess.access_token,
                           @"share_status" : @"0"
                           };
    //你的接口地址
    NSString *url = [NSString stringWithFormat:@"%@%@", kRealmName,kNetUISwich];
    //发送请求
    [manager POST:url parameters:para success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        [HUD hideAnimated:YES];
        
        NSDictionary *dic = responseObject;
        
        self.status = dic[@"status"];
        
        self.msg = dic[@"msg"];
        
        [self resultAnalysis];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        [HUD hideAnimated:YES];
        
        //初始化提示框；
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"没有网络" preferredStyle:  UIAlertControllerStyleAlert];
        
        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            //点击按钮的响应事件；
        }]];
        
        //弹出提示框；
        [self presentViewController:alert animated:true completion:nil];
        
    }];
    
}

//==============================================================================
#pragma mark 返回值分析
- (void) resultAnalysis {
    
    int status = [self.status intValue];
    
    switch (status) {
        case 99:{
            //初始化提示框；
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:self.msg preferredStyle:  UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                //点击按钮的响应事件；
            }]];
            
            //弹出提示框；
            [self presentViewController:alert animated:true completion:nil];
            
        }
            
            break;
        case 98:{
            
            //初始化提示框；
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:self.msg preferredStyle:  UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                //点击按钮的响应事件；
            }]];
            
            //弹出提示框；
            [self presentViewController:alert animated:true completion:nil];
            
        }
            break;
        case 97:
        {
            //初始化提示框；
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:self.msg preferredStyle:  UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                //点击按钮的响应事件；
            }]];
            
            //弹出提示框；
            [self presentViewController:alert animated:true completion:nil];
            
        }
            
            break;
        case 96:
        {
            
            //初始化提示框；
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:self.msg preferredStyle:  UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                //点击按钮的响应事件；
            }]];
            
            //弹出提示框；
            [self presentViewController:alert animated:true completion:nil];
            
        }
            
            break;
        case 1:
        {
            //初始化提示框；
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:self.msg preferredStyle:  UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                //点击按钮的响应事件；
            }]];
            
            //弹出提示框；
            [self presentViewController:alert animated:true completion:nil];
            
        }
            break;
        case 2:
        {
            //初始化提示框；
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:self.msg preferredStyle:  UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                //点击按钮的响应事件；
            }]];
            
            //弹出提示框；
            [self presentViewController:alert animated:true completion:nil];
            
        }
            break;
        case 3:
        {
            //初始化提示框；
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:self.msg preferredStyle:  UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                //点击按钮的响应事件；
                
            }]];
            
            //弹出提示框；
            [self presentViewController:alert animated:true completion:nil];
            
            
        }
            break;
        case 4:
        {
            //初始化提示框；
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:self.msg preferredStyle:  UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                //点击按钮的响应事件；
                
            }]];
            
            //弹出提示框；
            [self presentViewController:alert animated:true completion:nil];
            
            
        }
            break;

        case 100:
        {
            
            //初始化提示框；
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:self.msg preferredStyle:  UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                //点击按钮的响应事件；
                
            }]];
            
            //弹出提示框；
            [self presentViewController:alert animated:true completion:nil];
            
            
        }
            break;
            
        default:
            break;
    }
    
    
    
}


//返回主页
- (void)backTpMainView{
    
    MainPageViewController *mainVC = [[MainPageViewController alloc] init];
    
    [self.navigationController pushViewController:mainVC animated:nil];
    
    
}

#pragma mark 键盘只能输入数字
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    return [self validateNumber:string];
}

- (BOOL)validateNumber:(NSString*)number {
    BOOL res = YES;
    NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
    int i = 0;
    while (i < number.length) {
        NSString * string = [number substringWithRange:NSMakeRange(i, 1)];
        NSRange range = [string rangeOfCharacterFromSet:tmpSet];
        if (range.length == 0) {
            res = NO;
            break;
        }
        i++;
    }
    return res;
}

//结束编辑,点击空白回收键盘
- (void)tap
{
    
    //回收键盘
    [self.view endEditing:YES];
    
}
#pragma mark 补充租金设置
- (void) ReplenishSetRenterMoney {
    
    //蒙板
    self.mengbanV = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    self.mengbanV.backgroundColor = [UIColor blackColor];
    
    self.mengbanV.alpha = 0.3;
    
    [self.view addSubview:self.mengbanV];
    
    //背景图
    self.bgView = [[ UIView alloc] initWithFrame:CGRectMake(kScreenWidthTen, kScreenHeightEight * 2.5, kScreenWidthTen * 8 , 165)];
    self.bgView.layer.cornerRadius = 5;
    self.bgView.layer.masksToBounds = YES;
    self.bgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.bgView];
    
    
    //标签
    self.RemindLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, kScreenWidthTen * 8, 45)];
    self.RemindLabel.text = @"修改租金";
    self.RemindLabel.layer.cornerRadius = 8;
    self.RemindLabel.textAlignment = NSTextAlignmentCenter;
    self.RemindLabel.textColor = [UIColor colorWithRed:102 / 255.0 green:102 / 255.0 blue:102 / 255.0 alpha:1];
    self.RemindLabel.font = [UIFont systemFontOfSize:18];
    [self.bgView addSubview:self.RemindLabel];
    
    //标签
    self.moneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 55, kScreenWidthTen * 2 - 2, 45)];
    self.moneyLabel.text = @"租金:";
    self.moneyLabel.layer.cornerRadius = 8;
    self.moneyLabel.textAlignment = NSTextAlignmentCenter;
    self.moneyLabel.textColor = [UIColor colorWithRed:102 / 255.0 green:102 / 255.0 blue:102 / 255.0 alpha:1];
    self.moneyLabel.font = [UIFont systemFontOfSize:18];
    [self.bgView addSubview:self.moneyLabel];

    //输入框
    self.setRentMoneyTextField = [[UITextField alloc] initWithFrame:CGRectMake(kScreenWidthTen * 2 - 0.5, 55, kScreenWidthTen * 5 + 0.5, 45.5)];
    self.setRentMoneyTextField.backgroundColor = [UIColor whiteColor];
    self.setRentMoneyTextField.delegate = self;
    self.setRentMoneyTextField.layer.borderWidth = 0.5;
    self.setRentMoneyTextField.layer.borderColor = [UIColor colorWithRed:215 / 255.0 green:215 / 255.0 blue:215 / 255.0 alpha:1].CGColor;
    self.setRentMoneyTextField.font = [UIFont systemFontOfSize:18];
    self.setRentMoneyTextField.keyboardType = UIKeyboardTypeNumberPad;
    [self.bgView addSubview:self.setRentMoneyTextField];
    
    //取消按钮
    self.cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.cancelBtn.backgroundColor = [UIColor whiteColor];
    self.cancelBtn.frame = CGRectMake(-1, 115, kScreenWidthTen * 4 + 1, 51) ;
    self.cancelBtn.layer.borderWidth = 0.5;
    self.cancelBtn.layer.borderColor = [UIColor colorWithRed:215 / 255.0 green:215 / 255.0 blue:215 / 255.0 alpha:1].CGColor;
    [self.cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [self.cancelBtn addTarget:self action:@selector(cancelBtnPush) forControlEvents:UIControlEventTouchUpInside];
    [self.cancelBtn setTitleColor:[UIColor colorWithRed:102 / 255.0 green:102 / 255.0 blue:102 / 255.0 alpha:1] forState:UIControlStateNormal];
    self.cancelBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [self.bgView addSubview:self.cancelBtn];
    
    //确认按钮
    self.confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.confirmBtn.backgroundColor  = [UIColor whiteColor];
    self.confirmBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    self.confirmBtn.frame = CGRectMake(kScreenWidthTen * 4 - 0.5, 115, kScreenWidthTen *4 + 1, 51) ;
    self.confirmBtn.layer.borderColor = [UIColor colorWithRed:215 / 255.0 green:215 / 255.0 blue:215 / 255.0 alpha:1].CGColor;
    self.confirmBtn.layer.borderWidth = 0.5;
    [self.confirmBtn setTitle:@"确定" forState:UIControlStateNormal];
    [self.confirmBtn setTitleColor:[UIColor colorWithRed:0 / 255.0 green:137 / 255.0 blue:225 / 255.0 alpha:1] forState:UIControlStateNormal];
    [self.confirmBtn addTarget:self action:@selector(confirmBtnPush) forControlEvents:UIControlEventTouchUpInside];
    [self.bgView addSubview:self.confirmBtn];

    
}


//取消
- (void) cancelBtnPush {
    //回收键盘
    [self.view endEditing:YES];
    
    [self.bgView removeFromSuperview];
    
    [self.mengbanV removeFromSuperview];
    
}

//确定
- (void) confirmBtnPush {
    //回收键盘
    [self.view endEditing:YES];
    [self NetworkRequestsUpdateRentMemberMoney];
    
}


#pragma mark 网络请求
- (void) NetworkRequestsUpdateRentMemberMoney{
    
    //初始化进度框，置于当前的View当中
    MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:HUD];
    HUD.label.text = @"正在加载";
    [HUD showAnimated:YES];//HUD开始
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    //申明返回的结果是json类型
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    //申明请求的数据是json类型
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    //如果报接受类型不一致请替换一致text/html或别的
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    Access_token *useAccess = [Access_token shareInstance];
    
    //传入的参数
    NSDictionary *para = @{
                           @"type" : @"1",
                           @"access_token" : useAccess.access_token,
                           @"rent_member_money" : self.setRentMoneyTextField.text
                           };
    //你的接口地址
    NSString *url = [NSString stringWithFormat:@"%@%@", kRealmName,kNetUpdateRenterMoney];
    //发送请求
    [manager POST:url parameters:para success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        [HUD hideAnimated:YES];
        
        
        NSDictionary *dic = responseObject;
        
        self.status = dic[@"status"];
        
        self.msg = dic[@"msg"];        
        
        [self resultAnalysisTwo];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        [HUD hideAnimated:YES];
        
        //初始化提示框；
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"没有网络" preferredStyle:  UIAlertControllerStyleAlert];
        
        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            //点击按钮的响应事件；
        }]];
        
        //弹出提示框；
        [self presentViewController:alert animated:true completion:nil];
        
    }];
    
}


#pragma mark 返回值分析
- (void) resultAnalysisTwo {
    
    int status = [self.status intValue];
    
    switch (status) {
        case 99:{
            //初始化提示框；
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:self.msg preferredStyle:  UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                //点击按钮的响应事件；
            }]];
            
            //弹出提示框；
            [self presentViewController:alert animated:true completion:nil];
            
        }
            
            break;
        case 98:{
            
            //初始化提示框；
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:self.msg preferredStyle:  UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                //点击按钮的响应事件；
            }]];
            
            //弹出提示框；
            [self presentViewController:alert animated:true completion:nil];
            
        }
            break;
        case 97:
        {
            //初始化提示框；
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:self.msg preferredStyle:  UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                //点击按钮的响应事件；
            }]];
            
            //弹出提示框；
            [self presentViewController:alert animated:true completion:nil];
            
        }
            
            break;
        case 96:
        {
            
            //初始化提示框；
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:self.msg preferredStyle:  UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                //点击按钮的响应事件；
            }]];
            
            //弹出提示框；
            [self presentViewController:alert animated:true completion:nil];
            
        }
            
            break;
        case 1:
        {
            //初始化提示框；
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:self.msg preferredStyle:  UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                //点击按钮的响应事件；
            }]];
            
            //弹出提示框；
            [self presentViewController:alert animated:true completion:nil];
            
        }
            break;
        case 2:
        {
            //初始化提示框；
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:self.msg preferredStyle:  UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                //点击按钮的响应事件；
            }]];
            
            //弹出提示框；
            [self presentViewController:alert animated:true completion:nil];
            
        }
            break;
        case 3:
        {
            //初始化提示框；
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:self.msg preferredStyle:  UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                //点击按钮的响应事件；
                
            }]];
            
            //弹出提示框；
            [self presentViewController:alert animated:true completion:nil];
            
            
        }
            break;
            
        case 100:
        {
            
            //初始化提示框；
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:self.msg preferredStyle:  UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                //点击按钮的响应事件；
                self.setShareMoney.text = self.setRentMoneyTextField.text;
                
                [self.bgView removeFromSuperview];
                
                [self.mengbanV removeFromSuperview];

                
            }]];
            
            //弹出提示框；
            [self presentViewController:alert animated:true completion:nil];
            
            
        }
            break;
            
        default:
            break;
    }
    
    
    
}















@end
